/**
 * 
 */
(function() {
    'use strict';

    angular
        .module('milkbeeApp')
        .config(stateConfig);

    stateConfig.$inject = ['$stateProvider'];

    function stateConfig($stateProvider) {
        $stateProvider
        .state('myprofile', {
        	parent: 'entity',
            url: '/my/profile',
            data: {
                authorities: ['ROLE_USER'],
                pageTitle: 'milkbeeApp.leaguer.detail.title'
            },
            views: {
                'content@': {
                    templateUrl: 'app/my/profile/profile.html',
                    controller: 'MyProfileController',
                    controllerAs: 'vm'
                }
            },
            resolve: {
                translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
                    $translatePartialLoader.addPart('leaguer');
                    return $translate.refresh();
                }],
                entity: ['$stateParams', 'MyProfile', function($stateParams, MyProfile) {
                    return MyProfile.get().$promise;
                }],
                previousState: ["$state", function ($state) {
                    var currentStateData = {
                        name: $state.current.name || 'leaguer',
                        params: $state.params,
                        url: $state.href($state.current.name, $state.params)
                    };
                    return currentStateData;
                }]
            }
        })
        .state('myprofile.edit', {
            parent: 'myprofile',
            url: '/edit',
            data: {
                authorities: ['ROLE_USER']
            },
            onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
                $uibModal.open({
                    templateUrl: 'app/my/profile/profile-dialog.html',
                    controller: 'ProfileDialogController',
                    controllerAs: 'vm',
                    backdrop: 'static',
                    size: 'lg',
                    resolve: {
                        entity: ['$stateParams','MyProfile', function($stateParams,MyProfile) {
                            return MyProfile.get({id : $stateParams.id}).$promise;
                        }]
                    }
                }).result.then(function() {
                    $state.go('^', {}, { reload: false });
                }, function() {
                    $state.go('^');
                });
            }]
        })
        .state('myprofile.avatar', {
        	parent: 'myprofile',
        	url: '/avatar',
        	data: {
        		authorities: ['ROLE_USER']
        	},
        	onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
        		$uibModal.open({
        			templateUrl: 'app/my/profile/avatar-dialog.html',
        			controller: 'MyAvatarDialogController',
        			controllerAs: 'vm',
        			backdrop: 'static',
        			size: 'lg',
        			resolve: {
        				entity: ['$stateParams','MyProfile', function($stateParams,MyProfile) {
        					return MyProfile.get({id : $stateParams.id}).$promise;
        				}]
        			}
        		}).result.then(function() {
        			$state.go('^', {}, { reload: false });
        		}, function() {
        			$state.go('^');
        		});
        	}]
        })

    }

})();
